package com.mobilg.dating;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;


public class Chatting_NFCActivity extends Activity {
    /** Called when the activity is first created. */
	
	String gender, searchedGender;
	private DbAdapter mDbHelper;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
		
        final Cursor mCursor;
        Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
        Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
        Button searchButton = (Button) findViewById(R.id.button1);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.genders_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner1.setAdapter(adapter);
        spinner2.setAdapter(adapter);
        
        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                Object item = parent.getItemAtPosition(pos);
                gender = item.toString();                
            }
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                Object item = parent.getItemAtPosition(pos);
                searchedGender = item.toString();                
            }
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        
        mDbHelper = new DbAdapter(this);
		mDbHelper.open();		
		mCursor= mDbHelper.fetchAllProfiles();
		
        
        searchButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {               
            	if(mCursor.getCount()>0){            		
            		//getPreferences of the user
            		mDbHelper.close();
            		Toast.makeText(Chatting_NFCActivity.this, "Already Member of The System", Toast.LENGTH_LONG).show();
            		
            		//getNearbySearchedGenderFromServer     
            		
            		//open map view - set their locations on the map
            		Intent mapIntent = new Intent(Chatting_NFCActivity.this, GoogleMapsActivity.class);            		
            		startActivity(mapIntent);
            		/*Intent intentProfile = new Intent(Chatting_NFCActivity.this,ProfileActivity.class);
                	intentProfile.putExtra("PROFILE_GENDER", gender);
                	intentProfile.putExtra("PREFERRED_GENDER", searchedGender);
            		startActivity(intentProfile);*/            		
            	}
            	else {
            		mDbHelper.close();
            		Toast.makeText(Chatting_NFCActivity.this, "New Member", Toast.LENGTH_LONG).show();
            		Intent intentProfile = new Intent(Chatting_NFCActivity.this,ProfileActivity.class);
                	intentProfile.putExtra("PROFILE_GENDER", gender);
                	intentProfile.putExtra("PREFERRED_GENDER", searchedGender);
            		startActivity(intentProfile);
            	}
            }
        });
       
        
    }
    
	
}